/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model.creature.plant.plugin;

import java.awt.Image;
import model.creature.plant.AOEBombPlant;
import model.game.GameInterface;
import model.map.cell.PlantableCell;
import model.utility.ImageUtility;

/**
 * a tomato plant
 *
 * Grows into a plant in one day, harvestable in another day.
 *
 * When harvested, it cannot detonate during the night.
 *
 * Can detonate once per night, dealing damage equal to the number of
 * times it has been watered so far * some constant,
 *
 * Dies in 15 days.
 *
 */
public class Lotus extends AOEBombPlant {

  private int watered_count_;

  public Lotus(GameInterface game, PlantableCell cell) {
    super(game, cell);
    watered_count_ = 0;
  }

  /**
   * Retrieves the fruit name from this plant when harvested
   */
  @Override
  protected String getFruitName() {
    return "Lotus Flower";
  }

  /**
   * Retrieves the days required to go from seed to mature
   */
  @Override
  protected int timeToMature() {
    return 1;
  }

  /**
   * Retrieves the days before this plant dies
   */
  @Override
  protected int timeToDie() {
    return 15;
  }

  /**
   * Retrieves the days before this plant can be harvested from mature state,
   * having beeing harvested harvest_count times before
   */
  @Override
  protected int timeToHarvest(int harvest_count) {
    return 1;
  }

  /**
   * Retrieves the HP of this plant at the given level
   * level can be accessed through getLevel()
   */
  @Override
  protected int getHPAtCurrentLevel() {
    return 25 + getLevel() * 25;
  }

  /**
   * Returns true iff plant can be upgraded again now
   * It's current level is given in getLevel()
   */
  @Override
  public boolean canUpgrade() {
    if (getLevel() < 3) return true;
    return false;
  }

  /**
   * Retrieves the price to upgrade this plant's level
   * It's current level is given in getLevel()
   * @requires canUpgrade()
   */
  @Override
  public int getUpgradeCost() {
    return getLevel() * 60 + 80;
  }

   /**
   * Returns the image sprite of this plant
   */
  @Override
  public Image getImage() {
    if (is_seed_) {
      return ImageUtility.loadImage("resources/pictures/plants/lotus/seed.png");
    } else if (isHarvestable()) {
      return ImageUtility.loadImage("resources/pictures/plants/lotus/harvestable.png");
    } else {
      return ImageUtility.loadImage("resources/pictures/plants/lotus/mature.png");
    }
  }

  /**
   * Returns the name of this plant
   * Primary Key
   */
  @Override
  public String getName() {
    return "Lotus";
  }

  /**
   * Return the season only during this season this plant may grow
   */
  @Override
  public String getSeason() {
    return "Summer";
  }

  /**
   * Returns the description of this plant
   */
  @Override
  public String getDescription() {
    return "Dies in 20 days. Grows in summer. Matures in 1 day, Harvestable everyday."
            + " When stepped on, detonates and inflict damage to all monsters"
            + " in radius " + getRadius() + " around it for damage equal to " + getBasePower() + ""
            + " times the number of times it has been watered since its last "
            + " detonation. Has been watered " + watered_count_ + " times."
            + " Can be stepped on.";
  }

  /**
   * Determines the multiplier of explosion damage
   */
  public int getBasePower() {
    return 80 + getLevel() * 50;
  }

  /**
   * Determines the dmaage done by a creature when attacking
   */
  @Override
  public int getPower() {
    return getBasePower() * watered_count_;
  }

  /**
   * Returns the radius of this plant's attacks
   *
   * I.e., this plant attack at most plantAttackCount() monsters whose
   * manhattan distance with this plant is less than or equal getRadius()
   */
  public int getRadius() {
    return 3;
  }

  /**
   * Returns the number of shots this plant performs each time.
   */
  public int getAttackCount() {
    return 100;
  }

  @Override
  public void uponDetonation() {
    watered_count_ = 0;
  }

  @Override
  public void uponAdvanceDay() {
    PlantableCell mycell = (PlantableCell)getCell();
    if (mycell.isWatered()) {
      ++watered_count_;
    }
  }

  @Override
  public boolean canDetonate() {
    return isHarvestable() && !game_.getCreatures().getMonsters().getAllMonstersAt(getCell()).isEmpty() &&
            watered_count_ != 0;
  }

}
